package com.liming.user.controller;

import com.liming.common.enums.MiniProductPageQueryEnum;
import com.liming.common.pojo.dto.PageDTO;
import com.liming.common.pojo.dto.product.MiniProductPageQuery;
import com.liming.common.pojo.vo.PageVO;
import com.liming.common.pojo.vo.product.CategoryVO;
import com.liming.common.pojo.vo.product.MiniProductDetailVO;
import com.liming.common.pojo.vo.product.MiniProductPageQueryVO;
import com.liming.common.pojo.vo.product.MiniProductVO;
import com.liming.common.result.LMResult;
import com.liming.user.service.ProductService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author liming
 * @date 2025/3/20
 */
@Slf4j
@RestController
@AllArgsConstructor
@Tag(name = "商品接口-Web")
@RequestMapping("/user/product")
public class ProductController {

    private final ProductService productService;

    @Operation(
            summary = "推荐商品",
            responses = {
                    @ApiResponse(responseCode = "1", description = "推荐商品", content = {
                            @Content(mediaType = "application/json", schema = @Schema(implementation = MiniProductVO.class))
                    })
            }
    )
    @GetMapping("recommend")
    public LMResult<List<MiniProductVO>> recommend() {
        return LMResult.success(productService.recommend());
    }

    @Operation(
            summary = "商品详情",
            responses = {
                    @ApiResponse(responseCode = "1", description = "商品详情", content = {
                            @Content(mediaType = "application/json", schema = @Schema(implementation = MiniProductDetailVO.class))
                    })
            }
    )
    @GetMapping("detail/{id}")
    public LMResult<MiniProductDetailVO> detail(@PathVariable Long id) {
        return LMResult.success(productService.detail(id));
    }

    @Operation(
            summary = "分页 - 商品查询条件",
            responses = {
                    @ApiResponse(responseCode = "1", description = "分页 - 商品查询条件", content = {
                            @Content(mediaType = "application/json", schema = @Schema(implementation = MiniProductPageQueryVO.class))
                    })
            }
    )
    @GetMapping("pageQuery")
    public LMResult<List<MiniProductPageQueryVO>> pageQuery() {
        return LMResult.success(MiniProductPageQueryEnum.pageQuery());
    }

    @Operation(
            summary = "分页 - 商品分类查询列表",
            responses = {
                    @ApiResponse(responseCode = "1", description = "商品列表", content = {
                            @Content(mediaType = "application/json", schema = @Schema(implementation = CategoryVO.class))
                    })
            }
    )
    @GetMapping("pageCategoryQuery")
    public LMResult<PageVO<CategoryVO>> pageCategoryQuery(PageDTO page) {
        return LMResult.success(productService.pageCategoryQuery(page));
    }


    @Operation(
            summary = "分页 - 商品",
            responses = {
                    @ApiResponse(responseCode = "1", description = "商品列表", content = {
                            @Content(mediaType = "application/json", schema = @Schema(implementation = MiniProductVO.class))
                    })
            }
    )
    @GetMapping("miniPage")
    public LMResult<PageVO<MiniProductVO>> page(MiniProductPageQuery query) {
        return LMResult.success(productService.page(query));
    }
}
